﻿// DlgFloor.cpp: 实现文件
//

#include "stdafx.h"
#include "GHCY.h"
#include "DlgFloor.h"
#include "afxdialogex.h"
#include "Floors.h"


// DlgFloor 对话框

IMPLEMENT_DYNAMIC(DlgFloor, CDialogEx)

DlgFloor::DlgFloor(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_FLOORS, pParent)
	, m_nSerect(0)
	, m_fX(0)
	, m_fY(0)
	, m_fA(0)
{
}

DlgFloor::~DlgFloor()
{
}

void DlgFloor::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_CBIndex(pDX, IDC_COMBO1, m_nSerect);
	DDX_Text(pDX, IDC_EDIT1, m_fX);
	DDX_Text(pDX, IDC_EDIT2, m_fY);
	DDX_Text(pDX, IDC_EDIT3, m_fA);
	DDX_Control(pDX, IDC_COMBO1, m_comboxFloor);
}


BEGIN_MESSAGE_MAP(DlgFloor, CDialogEx)
	ON_CBN_SELCHANGE(IDC_COMBO1, &DlgFloor::OnCbnSelchangeCombo1)
	//ON_BN_CLICKED(IDOK, &DlgFloor::OnBnClickedOk)
	ON_BN_CLICKED(IDOK2, &DlgFloor::OnBnClickedOk2)
END_MESSAGE_MAP()


// DlgFloor 消息处理程序


void DlgFloor::OnCbnSelchangeCombo1()
{
	UpdateData(1);
	Floor* pfl = &afxFloors.m_arrFloors[m_nSerect];
	ASSERT(pfl);
	m_fX = pfl->fX;
	m_fY = pfl->fY;
	m_fA = pfl->fA;

	UpdateData(0);
}


//void DlgFloor::OnBnClickedOk()
//{
//	OnBnClickedOk2();
//
//	if (m_nSerect == -1)
//	{
//		return;
//	}
//
//	EndDialog(IDOK);
//}


BOOL DlgFloor::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	for (size_t i = 0, length = afxFloors.m_arrFloors.GetCount(); i < length; i++)
	{
		CString str;
		str.Format(L"%i", afxFloors.m_arrFloors[i].nFloor);
		m_comboxFloor.AddString(str);
	}

	//m_comboxFloor.SetCurSel(0);

	return TRUE;  // return TRUE unless you set the focus to a control
				  // 异常: OCX 属性页应返回 FALSE
}


void DlgFloor::OnBnClickedOk2()
{
	UpdateData();

	if (m_nSerect == -1)
	{
		AfxMessageBox(L"请选择楼层");
		return;
	}

	Floor* pfl = &afxFloors.m_arrFloors[m_nSerect];
	pfl->fX = m_fX;
	pfl->fY = m_fY;
	pfl->fA = m_fA;
	pfl->setMatrix();

	CString strsql;
	strsql.Format(L"UPDATE `floors` set `xMap` = %f, `yMap` = %f, `aMap` = %f WHERE `floor` = %i;",
		m_fX, m_fY, m_fA, pfl->nFloor
	);
	theApp.getDatabase()->Execute(strsql);	// ?? 异常处理 	// 20201118合并成一条SQL
}
